<% layout('/layouts/default.html', {title: '部门管理', libs: ['validate','fileupload']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header">
			<div class="box-title">
				<i class="fa icon-grid"></i> ${text(office.isNewRecord ? '新增部门' : '编辑部门')}
			</div>
			<div class="box-tools pull-right">
				<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
			</div>
		</div>
		<#form:form id="inputForm" model="${office}" action="${ctx}/sys/office/save" method="post" class="form-horizontal">
			<div class="box-body">
				<div class="form-unit">${text('基本信息')}</div>
				<div class="row">
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required ">*</span> ${text('部门编号')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <#form:hidden path="isNewRecord"/>
                                <#form:hidden path="officeCode" id="officeCode"/>
                                <#form:input path="viewCode" maxlength="64" readonly="true" class="form-control required abc"/>
                            </div>
                        </div>
                    </div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('部门名称')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="officeName" maxlength="100" class="form-control required "/>
							</div>
						</div>
					</div>
				</div>
                <div class="row">
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required ">*</span> ${text('归属公司')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <#form:hidden path="oldCompany" id="oldCompany"/>
                                <#form:treeselect id="company" title="${text('公司选择')}"
                                path="company.companyCode" labelPath="company.companyName"
                                url="${ctx}/sys/company/treeData?ctrlPermi=${@Global.getConfig('user.adminCtrlPermi', '2')}"
                                btnClass="" class="required" allowClear="true" canSelectRoot="true" canSelectParent="true"/>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4">${text('上级部门')}：</label>
                            <div class="col-sm-8">
                                <#form:hidden path="oldOffice" id="oldOffice"/>
                                <#form:treeselect id="parent" title="${text('上级部门')}"
                                path="parent.id" labelPath="parent.officeName"
                                url="${ctx}/sys/office/treeData?excludeCode=${office.id}&ctrlPermi=${@Global.getConfig('user.adminCtrlPermi', '2')}&companyCode="
                                class="" allowClear="true" canSelectRoot="true" canSelectParent="true"/>
                            </div>
                        </div>
                    </div>
                </div>

                <#form:hidden path="fullName" id="fullName" maxlength="200" class="form-control"/>
                <!--<div class="row">
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required ">*</span> ${text('部门全称')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                               orm:input path="fullName" maxlength="200" class="form-control required "/>
                            </div>
                        </div>
                    </div>
                   <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required ">*</span> ${text('排序号')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <#form:input path="treeSort" maxlength="10" class="form-control required digits"/>
                            </div>
                        </div>
                    </div>
				</div>-->
				<div class="row" style="display: none">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('部门类型')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="officeType" dictType="sys_office_type" class="form-control required " />
							</div>
						</div>
					</div>
				</div>
                <div class="row">
                    <div class="col-xs-12">
                        <div class="form-group">
                            <label class="control-label col-sm-2" title="">
                                <span class="required hide">*</span> ${text('备注')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-10">
                                <#form:textarea path="remarks" rows="4" maxlength="500" class="form-control "/>
                            </div>
                        </div>
                    </div>
                </div>
				<div class="form-unit">${text('附件信息')}</div>
				<!--<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('负责人')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="leader" maxlength="100" class="form-control "/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('办公电话')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="phone" maxlength="100" class="form-control phone"/>
							</div>
						</div>
					</div>
				</div>-->
				<!--<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('联系地址')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="address" maxlength="255" class="form-control "/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('邮政编码')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="zipCode" maxlength="100" class="form-control zipCode"/>
							</div>
						</div>
					</div>
				</div>-->
				<!--<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('电子邮箱')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="email" maxlength="300" class="form-control email"/>
							</div>
						</div>
					</div>
					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2" title="">
								<span class="required hide">*</span> ${text('备注信息')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-10">
								<#form:textarea path="remarks" rows="4" maxlength="500" class="form-control "/>
							</div>
						</div>
					</div>
				</div>-->
                <div class="row">
                    <div class="col-xs-12">
                        <div class="form-group">
                            <label class="control-label col-sm-2">附件上传：</label>
                            <div class="col-sm-10">
                                <#form:fileupload id="uploadFile" bizKey="${office.id}" bizType="office_file"
                                uploadType="all" class="" readonly="false" preview="true"/>
                            </div>
                        </div>
                    </div>
                </div>
				<div class="form-unit">${text('系统信息')}</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('创建日期')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="createDate" class="form-control" disabled="true"
                                dataFormat="datetime2" data-type="datetime" data-format="yyyy-MM-dd HH:mm:ss"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('创建人')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="createBy" class="form-control" disabled="true"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('最后修改日期')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="updateDate" class="form-control" disabled="true"
                                dataFormat="datetime2" data-type="datetime" data-format="yyyy-MM-dd HH:mm:ss"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('最后修改人')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="updateBy" class="form-control" disabled="true"/>
							</div>
						</div>
						<div>
						</div>
<!--				<#form:extend collapsed="true" />-->
			</div>
			<div class="box-footer">
				<div class="row">
					<div class="col-sm-offset-2 col-sm-10">
						<% if (hasPermi('sys:office:edit')){ %>
							<button type="submit" class="btn btn-sm btn-primary" id="btnSubmit"><i class="fa fa-check"></i> ${text('保 存')}</button>&nbsp;
						<% } %>
						<button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('关 闭')}</button>
					</div>
				</div>
			</div>
		</#form:form>
	</div>
</div>
<% } %>
<script>
$("#inputForm").validate({
	submitHandler: function(form){
		js.ajaxSubmitForm($(form), function(data){
			js.showMessage(data.message);
			if(data.result == Global.TRUE){
				js.closeCurrentTabPage(function(contentWindow){
					(contentWindow.win||contentWindow).$('#dataGrid').dataGrid('refreshTreeChildren',
							$('#parentCode').val(), '${office.id}');
				});
			}
		}, "json");
    }
});
$('#officeName').change(function(){
	if ($('#fullName').val()==''){
		$('#fullName').val($(this).val());
	}
});

$(function () {
    var companyCode = $('#companyCode').val();
    var parentCode = $('#parentCode').val();
    $('#oldCompany').val(companyCode);
    $('#oldOffice').val(parentCode);
    var url = $("#parentDiv").attr("data-url").match(/(\S*)companyCode=/)[1];
    $("#parentDiv").attr("data-url",url+"companyCode="+companyCode);
});
// 选择上级节点回调方法
function treeselectCallback(id, act, index, layero){
	if (id == 'parent' && (act == 'ok' || act == 'clear')){
		// 创建并初始化下一个节点信息，如：排序号、默认值
		$.get('${ctx}/sys/office/createNextNode?parentCode='
				+$('#parentCode').val(), function(data){
			$('#treeSort').val(data.treeSort);
		});
	}
}

$("#companyCode").change(function () {
    var companyCode = $('#companyCode').val();
    var url = $("#parentDiv").attr("data-url").match(/(\S*)companyCode=/)[1];
    $("#parentDiv").attr("data-url",url+"companyCode="+companyCode);
});
</script>